-
Notifications
You must be signed in to change notification settings - Fork 39
Adding Auth0.AuthenticationApi
package dependency
#148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
while (true) | ||
{ | ||
_logger.LogDebug($"Polling CIBA token endpoint for auth_req_id: {initDetails.AuthRequestId} "); | ||
try | ||
{ | ||
var response = await _authenticationApiClient.GetTokenAsync(request); | ||
|
||
return new CibaCompletionDetails | ||
{ | ||
AccessToken = response.AccessToken, | ||
IdToken = response.IdToken, | ||
TokenType = response.TokenType, | ||
Scope = response.Scope, | ||
ExpiresIn = response.ExpiresIn, | ||
RefreshToken = response.RefreshToken, | ||
IsSuccessful = true, | ||
IsAuthenticationPending = false, | ||
}; | ||
} | ||
catch (ErrorApiException ex) | ||
{ | ||
_logger.LogWarning( | ||
ex, | ||
$"CIBA polling error for auth_req_id: {initDetails.AuthRequestId}." + | ||
$" Error: {ex.ApiError.Error}, Description: {ex.ApiError.Message}"); | ||
|
||
if (ex.ApiError.Error.Contains("authorization_pending", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
await Task.Delay(TimeSpan.FromSeconds(initDetails.Interval ?? 5)); | ||
continue; | ||
} | ||
|
||
return new CibaCompletionDetails | ||
{ | ||
IsAuthenticationPending = false, | ||
Error = ex.ApiError.Error, | ||
ErrorMessage = ex.ApiError.Message, | ||
IsSuccessful = false | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naive question: 🙂 Is this safe?
I'm always scared by while (true)
🙂 It doesn't explicitly communicate the termination criteria.
I suggest something like the following, but feel free to ignore my comment:
while (true) | |
{ | |
_logger.LogDebug($"Polling CIBA token endpoint for auth_req_id: {initDetails.AuthRequestId} "); | |
try | |
{ | |
var response = await _authenticationApiClient.GetTokenAsync(request); | |
return new CibaCompletionDetails | |
{ | |
AccessToken = response.AccessToken, | |
IdToken = response.IdToken, | |
TokenType = response.TokenType, | |
Scope = response.Scope, | |
ExpiresIn = response.ExpiresIn, | |
RefreshToken = response.RefreshToken, | |
IsSuccessful = true, | |
IsAuthenticationPending = false, | |
}; | |
} | |
catch (ErrorApiException ex) | |
{ | |
_logger.LogWarning( | |
ex, | |
$"CIBA polling error for auth_req_id: {initDetails.AuthRequestId}." + | |
$" Error: {ex.ApiError.Error}, Description: {ex.ApiError.Message}"); | |
if (ex.ApiError.Error.Contains("authorization_pending", StringComparison.OrdinalIgnoreCase)) | |
{ | |
await Task.Delay(TimeSpan.FromSeconds(initDetails.Interval ?? 5)); | |
continue; | |
} | |
return new CibaCompletionDetails | |
{ | |
IsAuthenticationPending = false, | |
Error = ex.ApiError.Error, | |
ErrorMessage = ex.ApiError.Message, | |
IsSuccessful = false | |
}; | |
} | |
} | |
var cibaCompletionDetails = new CibaCompletionDetails | |
{ | |
IsSuccessful = false, | |
IsAuthenticationPending = true, | |
}; | |
while (!cibaCompletionDetails.IsSuccessful && cibaCompletionDetails.IsAuthenticationPending) | |
{ | |
_logger.LogDebug($"Polling CIBA token endpoint for auth_req_id: {initDetails.AuthRequestId} "); | |
try | |
{ | |
var response = await _authenticationApiClient.GetTokenAsync(request); | |
cibaCompletionDetails.AccessToken = response.AccessToken; | |
cibaCompletionDetails.IdToken = response.IdToken; | |
cibaCompletionDetails.TokenType = response.TokenType; | |
cibaCompletionDetails.Scope = response.Scope; | |
cibaCompletionDetails.ExpiresIn = response.ExpiresIn; | |
cibaCompletionDetails.RefreshToken = response.RefreshToken; | |
cibaCompletionDetails.IsSuccessful = true; | |
cibaCompletionDetails.IsAuthenticationPending = false; | |
} | |
catch (ErrorApiException ex) | |
{ | |
_logger.LogWarning( | |
ex, | |
$"CIBA polling error for auth_req_id: {initDetails.AuthRequestId}." + | |
$" Error: {ex.ApiError.Error}, Description: {ex.ApiError.Message}"); | |
if (ex.ApiError.Error.Contains("authorization_pending", StringComparison.OrdinalIgnoreCase)) | |
{ | |
await Task.Delay(TimeSpan.FromSeconds(initDetails.Interval ?? 5)); | |
continue; | |
} | |
cibaCompletionDetails.IsAuthenticationPending = false; | |
cibaCompletionDetails.Error = ex.ApiError.Error; | |
cibaCompletionDetails.ErrorMessage = ex.ApiError.Message; | |
cibaCompletionDetails.IsSuccessful = false; | |
} | |
} | |
return cibaCompletionDetails; |
@@ -444,3 +444,97 @@ public class LogoutModel : PageModel | |||
} | |||
} | |||
``` | |||
|
|||
# Accessing Auth0.AuthenticationApi features | |||
`Auth0.AuthenticationApi` package is our standalone Authentication package that supports a wide range of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`Auth0.AuthenticationApi` package is our standalone Authentication package that supports a wide range of | |
`Auth0.AuthenticationApi` package is our standalone Authentication package that supports a wide range of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some suggestions to improve the presentation of the new supported features.
In particular, a reference to the two new sections in the table of contents of the EXAMPLES.md
file is missing
EXAMPLES.md
Outdated
|
||
# Accessing Auth0.AuthenticationApi features | ||
`Auth0.AuthenticationApi` package is our standalone Authentication package that supports a wide range of | ||
options for Authentication. We can access these features like below : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to give some context of what you are showing below.
options for Authentication. We can access these features like below : | |
options for Authentication. For example, you can use it to implement the [client credentials flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow), as shown below : |
EXAMPLES.md
Outdated
@@ -444,3 +444,97 @@ public class LogoutModel : PageModel | |||
} | |||
} | |||
``` | |||
|
|||
# Accessing Auth0.AuthenticationApi features |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a reference to this section in the table of contents at the top of this doc.
EXAMPLES.md
Outdated
} | ||
``` | ||
|
||
# Accessing specific features like CIBA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a reference to this section in the table of contents at the top of this doc.
I would just say:
# Accessing specific features like CIBA | |
# Using CIBA |
EXAMPLES.md
Outdated
/// Program.cs / Startup.cs | ||
builder.Services.AddAuth0WebAppAuthentication(options => | ||
{ | ||
options.Domain = "domain"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this required too? 🤔
EXAMPLES.md
Outdated
LoginHint = new LoginHint() | ||
{ | ||
Format = "iss_sub", | ||
Issuer = "https://dx-sdks-testing.us.auth0.com/", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to leave this URL here or indicate as follows:
Issuer = "https://dx-sdks-testing.us.auth0.com/", | |
Issuer = https://domain", //replace "domain" with your Auth0 domain |
Description
Auth0.AuthenticationApi
package as a direct dependency.Auth0.AuthenticationApi
without adding/managing a separate reference.AuthenticationApiClient
.Auth0CibaService
that the developers can register as dependency. It simplifies the CIBA flows and provides a default polling mechanism that the users can opt for. It also provides flexibility for the users to have their own polling mechanism.Auth0CibaService
.Internal References
Testing
Checklist
main